import pygame

class Aline():
    """说明外星人的类"""
    def __init__(self, ai_game):
        """初始化外星人"""
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        self.screen_rect = ai_game.screen.get_rect()

        # 导入外星人图像并获取其外接矩形
        self.image = pygame.image.load('picture/alien.bmp')
        self.rect = self.image.get_rect()

        # 确定外星人的出现位置
        self.rect.midtop = self.screen_rect.midtop

        # 在外星人的x中储存一个浮点数
        self.x = float(self.rect.x)

        # 移动标志
        self.moving_right = False
        self.moving_left = False
        self.moving_up = False
        self.moving_down = False

    def aline_update(self):
        """根据移动标志移动外星人"""
        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.rect.x += self.settings.ship_speed
        if self.moving_left and self.rect.left > 0:
            self.rect.x -= self.settings.ship_speed
        if self.moving_up and self.rect.y > 0:
            self.rect.y -= self.settings.ship_speed
        if self.moving_down and self.rect.y < 750:
            self.rect.y += self.settings.ship_speed

    def draw_aline(self):
        """在指定位置绘制外星人"""
        self.screen.blit(self.image, self.rect)



